home *** CD-ROM | disk | FTP | other *** search
- Path: news.flex.com.au!news
- From: cobweb@flex.com.au (Tony L)
- Newsgroups: comp.lang.c++
- Subject: Help Please
- Date: Thu, 11 Apr 1996 03:53:06 GMT
- Organization: Flex Information Technology
- Message-ID: <4ki39v$30s@daisy.flex.com.au>
- NNTP-Posting-Host: slip1-12.flex.com.au
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi all,
-
- The following is a very simple little program that I'm doing.
-
- Could someone please have a quick look through it and please tell me
- how I can get the 10th option to work. I can't figure out what to do
- if a person chooses number 10. I know that it is not refered to as a
- character seeing it contains 2 chars. But I'm lost :-)
-
- btw, could you also just quickly tell me if I have declared everything
- ok. Should "weight" and "total" be declared as a "float"?
-
- Also, I know I'm pushing my luck here asking sooo many questions, but
- could you also please tell me what is the best way to make the program
- loop. Should I use a "do... while loop", or do I just need a "while"
- loop?
-
- Thank you very much for your help....
-
- // This Program allows a person to enter their weight and it will
- // output their weight on other Planets....
-
- #include <stdio.h>
- #include <conio.h>
-
- main()
- {
- char first[25], last[25];
- float weight, total;
- char choice;
-
- clrscr();
- textcolor(YELLOW);cprintf(" Weighing On Different Planets");
- printf("\n\nWhat is your first name please? ");
- scanf(" %s", first);
- printf("\nWhat is your last name please? ");
- scanf(" %s", last);
- printf("\nGreetings, %s %s! How many pounds do you weight? ", first,
- last);
- scanf(" %f", &weight);
- printf("\nPick the number of the Planet you want to weigh in on:\n ");
- printf("\n 1. Mercury 6. Saturn" );
- printf("\n 2. Venus 7. Uranus" );
- printf("\n 3. Earth 8. Neptune" );
- printf("\n 4. Mars 9. Pluto " );
- printf("\n 5. Jupiter 10. The Moon");
-
- printf("\n\nPlease select a number: ");
- scanf(" %c", &choice);
- switch (choice)
- { case ('1') : total = (weight * .4);
- printf("On Mercury you would weigh %.2f Pounds", total);
- break;
- case ('2') : total = (weight * .9);
- printf("On Venus you would weigh %.2f Pounds", total);
- break;
- case ('3') : printf("On Earth you would weigh %.2f Pounds of
- course", weight);
- break;
- case ('4') : total = (weight * .4);
- printf("On Mars you would weigh %.2f Pounds", total);
- break;
- case ('5') : total = (weight * 2.5);
- printf("On Venus you would weigh %.2f Pounds", total);
- break;
- case ('6') : total = (weight * .9);
- printf("On Saturn you would weigh %.2f Pounds", total);
- break;
- case ('7') : total = (weight * .8);
- printf("On Uranus you would weigh %.2f Pounds", total);
- break;
- case ('8') : total = (weight * 1.2);
- printf("On Neptune you would weigh %.2f Pounds", total);
- break;
- case ('9') : total = (weight * .06);
- printf("On Pluto you would weigh %.2f Pounds", total);
- break;
- case ('10') : total = (weight * .17);
- printf("On the Moon you would weigh %.2f Pounds", total);
- break;
-
- default : printf("That's an INVALID Request sorry!");
- }
-
- return 0;
- }
-
- Once again, thank you....
-
-
- Regards,
- TonyL....
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-
- E-mail: cobweb@flex.com.au
- lamborghini@acslink.net.au
- URL: http://www.peg.apc.org/~lamborghini
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-